#pragma once
#pragma execution_character_set("utf-8")

#include <QFrame>
#include <QTimer>
#include "PLotDef.h"
#include "plotmodel.h"
#include "qcustomplot.h"
#include "plotdata.h"
#include <QSet>

class PlotGraphView  : public QCustomPlot
{
	Q_OBJECT
	Q_PROPERTY_CREATE(int, ShowModel);
public:
	PlotGraphView(QSharedPointer< PlotModel> ,QWidget *parent);
	~PlotGraphView();
	void InitUI();
	void Initconnect();
public slots:
	void chekStatusChanged_Slot(QSharedPointer<PlotData>& _data);
	void RemoveQCPAxisRectAll();
	void setModel(QSharedPointer<PlotModel> M) { _plotModel = M; }
signals:
	void updateClass();
	void changedPlotData(const QSharedPointer<PlotData>&);
protected:
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void contextMenuEvent(QContextMenuEvent* event) override;
	void wheelEvent(QWheelEvent* event) override;
private:
	void _changeAxis(QSharedPointer< PlotData> &);
	void _ShowModel();
	void _connectAllxAsix(bool on);
	bool _moveLine(QMouseEvent* event);
	bool _setTracer(double x);
private:
	QTimer _timer;
	QSharedPointer< PlotModel> _plotModel;
	QSharedPointer<PlotData>  _currentPlotData;
	QPointer<QCPItemStraightLine> _LefLine;//QCPItemStraightLine
	QCPAxisRect* _axisRect;
	//QSharedPointer<QCPItemStraightLine> _RightLine;//QCPItemStraightLine
	//QSharedPointer<QCPItemStraightLine> _ToopLine;
	//QSharedPointer<QCPItemStraightLine> _BottomLine;
	//QSet< QSharedPointer<PlotData>> _dataList;
	bool _LefLineMoveEn = false;
	QTimer _updateTimer;
	bool _updateTimerEn;
	bool _isPressed = false;
	QCustomPlot _p;
};
